<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">

<title>class MarcTools::MarcConverter - Rails Application Documentation</title>

<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../index.html">Home</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/MarcTools.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link"><a href="../Object.html">Object</a>
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-i-changeSubfieldCode">#changeSubfieldCode</a>
    
    <li><a href="#method-i-changeTag">#changeTag</a>
    
    <li><a href="#method-i-concat">#concat</a>
    
    <li><a href="#method-i-filter">#filter</a>
    
    <li><a href="#method-i-getElements">#getElements</a>
    
    <li><a href="#method-i-hash_to_marc">#hash_to_marc</a>
    
    <li><a href="#method-i-insertTag">#insertTag</a>
    
    <li><a href="#method-i-marc_to_hash">#marc_to_hash</a>
    
    <li><a href="#method-i-updateElements">#updateElements</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="../doc/README_FOR_APP.html">README_FOR_APP</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../MarcTools.html">MarcTools</a>
  
    <li><a href="../MarcTools/MarcConverter.html">MarcTools::MarcConverter</a>
  
    <li><a href="../ApplicationController.html">ApplicationController</a>
  
    <li><a href="../ApplicationHelper.html">ApplicationHelper</a>
  
    <li><a href="../CzController.html">CzController</a>
  
    <li><a href="../MarcconverterController.html">MarcconverterController</a>
  
    <li><a href="../Object.html">Object</a>
  
    <li><a href="../OracleController.html">OracleController</a>
  
    <li><a href="../PersonController.html">PersonController</a>
  
    <li><a href="../PersonHelper.html">PersonHelper</a>
  
    <li><a href="../RsqvHelper.html">RsqvHelper</a>
  
    <li><a href="../RsqvpreviewController.html">RsqvpreviewController</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class MarcTools::MarcConverter</h1>

  <div id="description" class="description">
    
  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    <!-- Methods -->
    
     <section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Public Instance Methods</h3>

    
      <div id="method-i-changeSubfieldCode" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">changeSubfieldCode</span><span
            class="method-args">(input_hash, oldtag,newtag)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="changeSubfieldCode-source">
            <pre><span class="ruby-comment"># File lib/MarcTools.rb, line 73</span>
 <span class="ruby-keyword">def</span> <span class="ruby-identifier">changeSubfieldCode</span>(<span class="ruby-identifier">input_hash</span>, <span class="ruby-identifier">oldtag</span>,<span class="ruby-identifier">newtag</span>)   
       <span class="ruby-identifier">t1</span>=<span class="ruby-identifier">oldtag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\$.*/</span>,<span class="ruby-string">&quot;&quot;</span>)
      <span class="ruby-identifier">c1</span>=<span class="ruby-identifier">oldtag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/.*\$/</span>, <span class="ruby-string">&quot;&quot;</span>)
      <span class="ruby-identifier">t2</span>=<span class="ruby-identifier">newtag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\$.*/</span>,<span class="ruby-string">&quot;&quot;</span>)
      <span class="ruby-identifier">c2</span>=<span class="ruby-identifier">newtag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/.*\$/</span>, <span class="ruby-string">&quot;&quot;</span>)
      <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t1</span>].<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
       
   <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t1</span>][<span class="ruby-identifier">k</span>][<span class="ruby-identifier">c2</span>]=<span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t1</span>][<span class="ruby-identifier">k</span>][<span class="ruby-identifier">c1</span>]
<span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t1</span>][<span class="ruby-identifier">k</span>].<span class="ruby-identifier">delete</span>([<span class="ruby-identifier">c1</span>])
}
<span class="ruby-identifier">input_hash</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- changeSubfieldCode-source -->
          
        </div>

        

        
      </div><!-- changeSubfieldCode-method -->

    
      <div id="method-i-changeTag" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">changeTag</span><span
            class="method-args">(input_hash,oldtag,newtag)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="changeTag-source">
            <pre><span class="ruby-comment"># File lib/MarcTools.rb, line 87</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">changeTag</span>(<span class="ruby-identifier">input_hash</span>,<span class="ruby-identifier">oldtag</span>,<span class="ruby-identifier">newtag</span>)
  <span class="ruby-identifier">input_hash</span>.<span class="ruby-identifier">keys</span>().<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">k</span><span class="ruby-operator">==</span><span class="ruby-identifier">oldtag</span>
      <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">newtag</span>]=<span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">k</span>]
      <span class="ruby-identifier">input_hash</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">k</span>)
    <span class="ruby-keyword">end</span>
  }
  <span class="ruby-identifier">input_hash</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- changeTag-source -->
          
        </div>

        

        
      </div><!-- changeTag-method -->

    
      <div id="method-i-concat" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">concat</span><span
            class="method-args">(input_hash,tag1, tag2, separator=" - ")</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="concat-source">
            <pre><span class="ruby-comment"># File lib/MarcTools.rb, line 43</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">concat</span>(<span class="ruby-identifier">input_hash</span>,<span class="ruby-identifier">tag1</span>, <span class="ruby-identifier">tag2</span>, <span class="ruby-identifier">separator</span>=<span class="ruby-string">&quot; - &quot;</span>)
  <span class="ruby-identifier">t1</span>=<span class="ruby-identifier">tag1</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\$.*/</span>,<span class="ruby-string">&quot;&quot;</span>)
        <span class="ruby-identifier">c1</span>=<span class="ruby-identifier">tag1</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/.*\$/</span>, <span class="ruby-string">&quot;&quot;</span>)
        <span class="ruby-identifier">t2</span>=<span class="ruby-identifier">tag2</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\$.*/</span>,<span class="ruby-string">&quot;&quot;</span>)
        <span class="ruby-identifier">c2</span>=<span class="ruby-identifier">tag2</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/.*\$/</span>, <span class="ruby-string">&quot;&quot;</span>)
        <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t1</span>].<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">new_string</span>=[<span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t1</span>][<span class="ruby-identifier">k</span>][<span class="ruby-identifier">c1</span>]<span class="ruby-operator">+</span><span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t1</span>][<span class="ruby-identifier">k</span>][<span class="ruby-identifier">c2</span>]]
        <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t1</span>][<span class="ruby-identifier">k</span>][<span class="ruby-identifier">c1</span>]=[<span class="ruby-identifier">new_string</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">separator</span>)]
  }
  <span class="ruby-identifier">input_hash</span>
        
  
  
<span class="ruby-keyword">end</span></pre>
          </div><!-- concat-source -->
          
        </div>

        

        
      </div><!-- concat-method -->

    
      <div id="method-i-filter" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">filter</span><span
            class="method-args">(input_hash, taglist=[])</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="filter-source">
            <pre><span class="ruby-comment"># File lib/MarcTools.rb, line 26</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">filter</span>(<span class="ruby-identifier">input_hash</span>, <span class="ruby-identifier">taglist</span>=[])
  <span class="ruby-identifier">taglist</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">tag</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">tag</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-string">&quot;$&quot;</span>)
      <span class="ruby-identifier">t</span>=<span class="ruby-identifier">tagname</span>(<span class="ruby-identifier">tag</span>)
                <span class="ruby-identifier">c</span>=<span class="ruby-identifier">codename</span>(<span class="ruby-identifier">tag</span>)
                <span class="ruby-keyword">if</span> <span class="ruby-identifier">input_hash</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">t</span>)
      <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>].<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>][<span class="ruby-identifier">k</span>].<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">c</span>)
      }
<span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">input_hash</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">tag</span>)
    <span class="ruby-keyword">end</span>
  }
  <span class="ruby-identifier">input_hash</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- filter-source -->
          
        </div>

        

        
      </div><!-- filter-method -->

    
      <div id="method-i-getElements" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">getElements</span><span
            class="method-args">(input_hash,tag)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="getElements-source">
            <pre><span class="ruby-comment"># File lib/MarcTools.rb, line 15</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">getElements</span>(<span class="ruby-identifier">input_hash</span>,<span class="ruby-identifier">tag</span>)
  <span class="ruby-identifier">t</span>=<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\$.*/</span>,<span class="ruby-string">&quot;&quot;</span>)
  <span class="ruby-identifier">c</span>=<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/.*\$/</span>, <span class="ruby-string">&quot;&quot;</span>)
  <span class="ruby-identifier">mylist</span>=[]
  <span class="ruby-identifier">positionlist</span>=<span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>].<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">sort</span>
  <span class="ruby-identifier">positionlist</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">pos</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">mylist</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>][<span class="ruby-identifier">pos</span>][<span class="ruby-identifier">c</span>]
  }
  <span class="ruby-identifier">mylist</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- getElements-source -->
          
        </div>

        

        
      </div><!-- getElements-method -->

    
      <div id="method-i-hash_to_marc" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">hash_to_marc</span><span
            class="method-args">(input_hash)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="hash_to_marc-source">
            <pre><span class="ruby-comment"># File lib/MarcTools.rb, line 161</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">hash_to_marc</span>(<span class="ruby-identifier">input_hash</span>)
  <span class="ruby-identifier">xml</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>()
  <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">root</span> = <span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;collection&quot;</span>)
  <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">root</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">record</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;record&quot;</span>)
  <span class="ruby-identifier">input_hash</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">tag</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">tag</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>]<span class="ruby-operator">==</span><span class="ruby-string">'00'</span>
      <span class="ruby-identifier">record</span>  <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">field</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;controlfield&quot;</span>)
      <span class="ruby-identifier">field</span>[<span class="ruby-string">'tag'</span>]=<span class="ruby-identifier">tag</span>
      <span class="ruby-identifier">field</span>.<span class="ruby-identifier">content</span>=<span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">tag</span>].<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;&quot;</span>)
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">tag</span><span class="ruby-operator">==</span><span class="ruby-string">'leader'</span>
      <span class="ruby-identifier">record</span>  <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">field</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;leader&quot;</span>)
      <span class="ruby-identifier">field</span>.<span class="ruby-identifier">content</span>=<span class="ruby-identifier">input_hash</span>[<span class="ruby-string">'leader'</span>]
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">tag</span>].<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">each</span>{
        <span class="ruby-operator">|</span><span class="ruby-identifier">pos</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">record</span>  <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">field</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;datafield&quot;</span>)
        <span class="ruby-identifier">field</span>[<span class="ruby-string">'tag'</span>]=<span class="ruby-identifier">tag</span>
        <span class="ruby-identifier">field</span>[<span class="ruby-string">'ind1'</span>]=<span class="ruby-string">&quot;  &quot;</span>
        <span class="ruby-identifier">field</span>[<span class="ruby-string">'ind2'</span>]=<span class="ruby-string">&quot;  &quot;</span>
        <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">tag</span>][<span class="ruby-identifier">pos</span>].<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">each</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">field</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">sub</span>=<span class="ruby-constant">LibXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Node</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;subfield&quot;</span>)
          <span class="ruby-identifier">sub</span>[<span class="ruby-string">'code'</span>]=<span class="ruby-identifier">c</span>
          <span class="ruby-identifier">sub</span>.<span class="ruby-identifier">content</span>=<span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">tag</span>][<span class="ruby-identifier">pos</span>][<span class="ruby-identifier">c</span>].<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;, &quot;</span>)
        }
      }
    <span class="ruby-keyword">end</span>
  }
  <span class="ruby-identifier">xml</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- hash_to_marc-source -->
          
        </div>

        

        
      </div><!-- hash_to_marc-method -->

    
      <div id="method-i-insertTag" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">insertTag</span><span
            class="method-args">(input_hash,tag, content)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="insertTag-source">
            <pre><span class="ruby-comment"># File lib/MarcTools.rb, line 98</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">insertTag</span>(<span class="ruby-identifier">input_hash</span>,<span class="ruby-identifier">tag</span>, <span class="ruby-identifier">content</span>)
  <span class="ruby-identifier">t</span>=<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\$.*/</span>,<span class="ruby-string">&quot;&quot;</span>)
  <span class="ruby-identifier">c</span>=<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/.*\$/</span>, <span class="ruby-string">&quot;&quot;</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">input_hash</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">t</span>)

    <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>].<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">pos</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>][<span class="ruby-identifier">pos</span>].<span class="ruby-identifier">update</span>({<span class="ruby-identifier">c</span> =<span class="ruby-operator">&gt;</span>[<span class="ruby-identifier">content</span>]})

    }
  <span class="ruby-keyword">end</span>
  <span class="ruby-comment">#}</span>
  <span class="ruby-identifier">input_hash</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- insertTag-source -->
          
        </div>

        

        
      </div><!-- insertTag-method -->

    
      <div id="method-i-marc_to_hash" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">marc_to_hash</span><span
            class="method-args">(xml_doc)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="marc_to_hash-source">
            <pre><span class="ruby-comment"># File lib/MarcTools.rb, line 112</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">marc_to_hash</span>(<span class="ruby-identifier">xml_doc</span>)
  <span class="ruby-comment">#Returns Marc_Hash</span>
  <span class="ruby-identifier">result_hash</span>={}
  <span class="ruby-identifier">tag</span>=<span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">cnt</span>=<span class="ruby-value">1</span>
  <span class="ruby-identifier">xml_doc</span>.<span class="ruby-identifier">each_element</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span>[<span class="ruby-string">'tag'</span>]
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span>[<span class="ruby-string">'tag'</span>]<span class="ruby-operator">==</span><span class="ruby-identifier">tag</span>
        <span class="ruby-identifier">cnt</span><span class="ruby-operator">+=</span><span class="ruby-value">1</span>
        <span class="ruby-identifier">code</span>={}
        <span class="ruby-identifier">e</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">attributes?</span>
            <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">code</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">s</span>[<span class="ruby-string">'code'</span>])
              <span class="ruby-identifier">code</span>[<span class="ruby-identifier">s</span>[<span class="ruby-string">'code'</span>]]=[<span class="ruby-identifier">s</span>.<span class="ruby-identifier">content</span>]
            <span class="ruby-keyword">else</span>
              <span class="ruby-identifier">code</span>[<span class="ruby-identifier">s</span>[<span class="ruby-string">'code'</span>]]<span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">s</span>.<span class="ruby-identifier">content</span>
            <span class="ruby-keyword">end</span>
            <span class="ruby-identifier">code</span>[<span class="ruby-identifier">s</span>[<span class="ruby-string">'code'</span>]]=[<span class="ruby-identifier">s</span>.<span class="ruby-identifier">content</span>]
          <span class="ruby-keyword">end</span>            }
        <span class="ruby-identifier">result_hash</span>[<span class="ruby-identifier">e</span>[<span class="ruby-string">'tag'</span>]][<span class="ruby-identifier">cnt</span>]=<span class="ruby-identifier">code</span>

      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">cnt</span>=<span class="ruby-value">1</span>
        <span class="ruby-identifier">code</span>={}

        <span class="ruby-keyword">if</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">name!</span>=<span class="ruby-string">'controlfield'</span>
          <span class="ruby-identifier">e</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
            <span class="ruby-keyword">if</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">attributes?</span>
              <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">code</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">s</span>[<span class="ruby-string">'code'</span>])
                <span class="ruby-identifier">code</span>[<span class="ruby-identifier">s</span>[<span class="ruby-string">'code'</span>]]=[<span class="ruby-identifier">s</span>.<span class="ruby-identifier">content</span>]
              <span class="ruby-keyword">else</span>
                <span class="ruby-identifier">code</span>[<span class="ruby-identifier">s</span>[<span class="ruby-string">'code'</span>]]<span class="ruby-operator">&lt;&lt;</span><span class="ruby-identifier">s</span>.<span class="ruby-identifier">content</span>
              <span class="ruby-keyword">end</span>
            <span class="ruby-keyword">end</span>
          }
          <span class="ruby-identifier">result_hash</span>.<span class="ruby-identifier">update</span>({<span class="ruby-identifier">e</span>[<span class="ruby-string">'tag'</span>]=<span class="ruby-operator">&gt;</span>{<span class="ruby-identifier">cnt</span>=<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">code</span>}})
          <span class="ruby-identifier">tag</span>=<span class="ruby-identifier">e</span>[<span class="ruby-string">'tag'</span>]
        <span class="ruby-keyword">else</span>
          <span class="ruby-identifier">result_hash</span>.<span class="ruby-identifier">update</span>({<span class="ruby-identifier">e</span>[<span class="ruby-string">'tag'</span>]=<span class="ruby-operator">&gt;</span>[<span class="ruby-identifier">e</span>.<span class="ruby-identifier">content</span>]})
        <span class="ruby-keyword">end</span>
      <span class="ruby-keyword">end</span>

    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">result_hash</span>.<span class="ruby-identifier">update</span>({<span class="ruby-string">'leader'</span>=<span class="ruby-operator">&gt;</span><span class="ruby-identifier">e</span>.<span class="ruby-identifier">content</span>})
    <span class="ruby-keyword">end</span>
  }
  <span class="ruby-identifier">result_hash</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- marc_to_hash-source -->
          
        </div>

        

        
      </div><!-- marc_to_hash-method -->

    
      <div id="method-i-updateElements" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">updateElements</span><span
            class="method-args">(input_hash,tag, func)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          
          

          
          <div class="method-source-code" id="updateElements-source">
            <pre><span class="ruby-comment"># File lib/MarcTools.rb, line 58</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">updateElements</span>(<span class="ruby-identifier">input_hash</span>,<span class="ruby-identifier">tag</span>, <span class="ruby-identifier">func</span>)
  <span class="ruby-identifier">t</span>=<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/\$.*/</span>,<span class="ruby-string">&quot;&quot;</span>)
  <span class="ruby-identifier">c</span>=<span class="ruby-identifier">tag</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp">/.*\$/</span>, <span class="ruby-string">&quot;&quot;</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">input_hash</span>.<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">t</span>)

    <span class="ruby-identifier">positionlist</span>=<span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>].<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">sort</span>
    <span class="ruby-identifier">positionlist</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">pos</span><span class="ruby-operator">|</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>][<span class="ruby-identifier">pos</span>].<span class="ruby-identifier">key?</span>(<span class="ruby-identifier">c</span>)
        <span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>][<span class="ruby-identifier">pos</span>][<span class="ruby-identifier">c</span>]=<span class="ruby-identifier">input_hash</span>[<span class="ruby-identifier">t</span>][<span class="ruby-identifier">pos</span>][<span class="ruby-identifier">c</span>].<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">func</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">e</span>)}
      <span class="ruby-keyword">end</span>
    }
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">input_hash</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- updateElements-source -->
          
        </div>

        

        
      </div><!-- updateElements-method -->

    
    </section><!-- public-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.12.2.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

